
#include "GameState/Master/Master.h"
#include "Engine/Backbone.h"
#include "GameState/Master/MainMenu.h"

#include "Engine/Synaptic/Sound.h" // TODO: temporary include, please work on Sound resource
namespace GameState {

namespace Master {

Master::Master() : 
	Sense("masterGameState"),
	Reason("masterGameState"),
	Visual("masterGameState"),
	background("masterBg", "screen/master", 0),
	mainMenu(Misc::Frame(235,340,180,70), 4),
	menuBackground("menuBackground", "screen/master")
	 {
	// Add menu entries
	mainMenu[0] = new EntryBegin(Misc::Frame(235,340,180,35));
	mainMenu[1] = new EntryOptions(Misc::Frame(235,385,180,35));
	mainMenu[2] = new EntryExit(Misc::Frame(235,430,180,35));
	
	mainMenu.active(true).hidden(false).focusAt(0);
	//mainMenu[1]->hidden(true).active(false);

	
	menuBackground.setPosition(225, 325);
	Engine::Synaptic::Sound::loadSound("sounds/menuChange.wav");
	Engine::Synaptic::Sound::loadSound("sounds/menuSelect.wav");
}

Master::~Master(){
}

void Master::pulse(int delta) {
}

// Asks for generation of a graphical model to be displayed

Engine::Resource::GraphicList Master::display() {
  Engine::Resource::GraphicList gfxList;
  gfxList.push_back(&background);
  return gfxList;
}

// Asks for generation of a graphical model to be displayed
void Master::keyDown(SDLKey sym, SDLMod mod, Uint16 unicode) {
	switch (sym) {
		case SDLK_RETURN:
			// enter in the selected entry
			mainMenu.select();
			Engine::Synaptic::Sound::play("sounds/menuSelect.wav");
			break;
		case SDLK_LEFT:
		case SDLK_UP:
			mainMenu.focusPrevious();
			Engine::Synaptic::Sound::play("sounds/menuChange.wav");
			break;
		case SDLK_RIGHT:
		case SDLK_DOWN:
			mainMenu.focusNext();
			Engine::Synaptic::Sound::play("sounds/menuChange.wav");
			break;
		default:
			break;
	}
}

Master * Master::singleInstance= NULL; // Single master screen instance

} // namespace GameState::Master

} // namespace GameState
